export default function paletteEntries (handTool, lassoTool, spaceTool, globalConnect) {
  return {
    'hand-tool': {
      group: 'tools',
      className: 'bpmn-icon-hand-tool',
      title: 'Activate the hand tool',
      action: {
        click: function (event) {
          handTool.activateHand(event)
        }
      }
    },
    'lasso-tool': {
      group: 'tools',
      className: 'bpmn-icon-lasso-tool',
      title: 'Activate the lasso tool',
      action: {
        click: function (event) {
          lassoTool.activateSelection(event)
        }
      }
    },
    'space-tool': {
      group: 'tools',
      className: 'bpmn-icon-space-tool',
      title: 'Activate the create/remove space tool',
      action: {
        click: function (event) {
          spaceTool.activateSelection(event)
        }
      }
    },
    'global-connect-tool': {
      group: 'tools',
      className: 'bpmn-icon-connection-multi',
      title: 'Activate the global connect tool',
      action: {
        click: function (event) {
          globalConnect.toggle(event)
        }
      }
    },
    'tool-separator': {
      group: 'tools',
      separator: true
    },

    'create.start-event': createAction(
      'bpmn:StartEvent',
      'event',
      'bpmn-icon-start-event-none',
      '创建开始节点'
    ),
    'create.end-event': createAction(
      'bpmn:EndEvent',
      'event',
      'bpmn-icon-end-event-none',
      '创建结束节点'
    ),
    'create.timer-intermediate-event': createAction(
      'bpmn:IntermediateThrowEvent',
      'event',
      'bpmn-icon-intermediate-event-catch-timer',
      '创建定时事件',
      { eventDefinitionType: 'bpmn:TimerEventDefinition' }
    ),
    'create.intermediate-catch-event': createAction(
      'bpmn:IntermediateThrowEvent',
      'event',
      'bpmn-icon-intermediate-event-none',
      'Create Intermediate/Boundary Event'
    ),
    'create.submit-task': createAction(
      'bpmn:UserTask',
      'activity',
      'bpmn-icon-user-task',
      '创建提交节点'
    ),
    'create.user-task': createAction(
      'bpmn:UserTask',
      'activity',
      'bpmn-icon-user-task',
      '创建用户任务'
    ),
    'create.service-task': createAction(
      'bpmn:ServiceTask',
      'activity',
      'bpmn-icon-service-task',
      '创建服务任务'
    ),
    'create.service-script-task': createAction(
      'bpmn:ServiceTask',
      'activity',
      'bpmn-icon-script-task',
      '创建脚本任务'
    ),
    'create.script-task': createAction(
      'bpmn:ScriptTask',
      'activity',
      'bpmn-icon-script-task',
      '创建脚本任务'
    ),
    'create.receivetask': createAction(
      'bpmn:ReceiveTask',
      'activity',
      'bpmn-icon-receive-task',
      '接收任务'
    ),
    'create.send-task': createAction(
      'bpmn:SendTask',
      'activity',
      'bpmn-icon-send-task',
      '消息任务'
    ),
    'create.exclusive-gateway': createAction(
      'bpmn:ExclusiveGateway',
      'gateway',
      'bpmn-icon-gateway-xor',
      '创建排他网关'
    ),
    'create.parallel-gateway': createAction(
      'bpmn:ParallelGateway',
      'gateway',
      'bpmn-icon-gateway-parallel',
      '创建并行网关'
    ),
    'create.inclusive-gateway': createAction(
      'bpmn:InclusiveGateway',
      'gateway',
      'bpmn-icon-inclusive-gateway',
      '创建包容网关'
    ),
    'create.group': createAction(
      'bpmn:Group',
      'collaboration',
      'bpmn-icon-group',
      '创建 Group'
    )
  }
}

function createAction (type, group, className, title, imageUrl) {
  // 还记得 CustomPalette.js 吗？便是这里回调 createListener 函数
  // if (action === 'click') {
  // handler(originalEvent, autoActivate, elementFactory, create)
  // }
  function createListener (event, autoActivate, elementFactory, create) {
    // console.log('createAction', event, autoActivate, elementFactory, create)
    // console.log(event.target.classList)
    // debugger
    // console.log('xxxxxxxxxxxxxxxxxxx')
    // console.log(event.target)
    // console.log(event.target.dataset.action)

    // const editAble = !['create.submit-task', 'create.start-event'].includes(event.target.dataset.action)

    var shape = elementFactory.createShape({ type, _dataAction: event.target.dataset.action })
    // shape.businessObject = {
    //   ...shape.businessObject,
    //   editable: false
    // }
    // shape.businessObject.editable = false
    // this.update
    console.log(shape)

    create.start(event, shape)
  }

  return {
    group: group,
    className: className,
    title: title,
    imageUrl, // 📌
    action: {
      dragstart: createListener,
      click: createListener
      // dbclick: () => {}
    }
  }
}
